import {promiseRequest} from "./index";
import authApi from "./authorization";

const api = {
  getFormLayout: async (id) => {
    const token = await authApi.updateLoginStatus();
    return (await promiseRequest(`/activity/form/${id}`, "GET", {
      header: {
        Authorization: `Bearer ${token}`
      }
    }))["data"]["items"]
  },
  async getSuccessImage(id){
    const token = await authApi.updateLoginStatus();
    return (await promiseRequest(`/activity/form/${id}/success`, "GET", {
      header: {
        Authorization: `Bearer ${token}`,
      },
    }))["data"];
  },
  async isSignUp(id) {
    const token = await authApi.updateLoginStatus();
    return (await promiseRequest(`/activity/form/${id}/isSignUp`, "GET", {
      header: {
        Authorization: `Bearer ${token}`,
      },
    }))["data"];
  },
  signUpActivity: async (id, formData) => {
    const token = await authApi.updateLoginStatus();
    return (await promiseRequest("/activity/form/fill", "POST", {
      header: {
        Authorization: `Bearer ${token}`,
      },
      data: {
        activity_id: id,
        answers: formData.map(e => ({
          question_id: e.id,
          answer: e.data,
        }))
      }
    }))["data"];
  }
}
export default api;
